<template>
	<view class="container">
		<view class="uni-padding-wrap">
			<uni-segmented-control :current="current" :values="items" :style-type="styleType"
				:active-color="activeColor" @clickItem="onClickItem" />
		</view>
		<view class="content">
			<view v-if="current === 0">
				<case-list-content :list-data="listData" :rows="rows" @click="itemClick">
				</case-list-content>
				<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
			</view>
			<view v-if="current === 1">
				<uni-section title="当天案件上报时段分析" type="line">
					<view class="charts-box">
					    <qiun-data-charts type="line" :chartData="chartData" :opts="opts"/>
					</view>
				</uni-section>
				<uni-section title="当天各类案件上报分析" type="line">
					<view class="charts-box">
					    <qiun-data-charts type="column" :chartData="chartData1" />
					</view>
				</uni-section>
			</view>
		</view>
	</view>
</template>

<script>
	import { getHandleCaseList } from '@/api/dums/caw/caseInfo.js'
	import { runSuperviceList } from '@/api/dums/caw/stat/workBench.js'
	export default {
		data() {
			return {
				items: ['实时案件', '数据监控'],
				current: 0,
				activeColor: '#2359C1',
				styleType: 'button',
				page:1,
				size:10,
				total:0,
				queryParams:{},
				listData: [],
				rows:[{
					labelName:"案件编号",
					valueName:"caseCode"
				},{
					labelName:"上报时间",
					valueName:"rptTime"
				},{
					labelName:"事件状态",
					valueName:"linkName"
				},{
					labelName:"事发位置",
					valueName:"casePosDesc"
				}],
				reload: false,
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				
				
				opts:{
					xAxis:{
						marginTop:5,
						rotateLabel:true,
						rotateAngle:45
					}
				},
				chartData: {},
				chartData1: {},
			}
		},
		methods: {
			onClickItem(e){
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
					if(this.current == 1){
						this.getServerData();
					}
				}
			},
			getList() {
				uni.showLoading({
					title:"加载中"
				})
				if (this.total && !this.reload) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
				}
				if(this.reload){
					uni.stopPullDownRefresh();
				}
				this.queryParams.pageSize = this.size;
				this.queryParams.pageNum = this.page;
				//只查当天上报的案件
				let params = {
					"rptTimeStart":this.parseTime(new Date().getTime(),'{y}-{m}-{d}')+" 00:00:00",
					"rptTimeEnd":this.parseTime(new Date().getTime(),'{y}-{m}-{d}')+" 23:59:59"
				}
				this.queryParams.params = params;
				getHandleCaseList(this.queryParams).then(res => {
					uni.hideLoading();
					if(res.code == 200){
						let list = res.rows;
						this.total = res.total;
						console.log(JSON.stringify(list));
						this.listData = this.reload ? list : this.listData.concat(list);
						this.reload = false;
					}
				})
			},
			itemClick(item){
				uni.navigateTo({
					url:'../case-detail/case-detail?caseId='+item.caseId
				})
			},
			getServerData() { 
				let params = {
					type:"reportForRptTime",
					startTime:this.parseTime(new Date().getTime(),'{y}-{m}-{d}'),
					endTime:this.parseTime(new Date().getTime()+86400000,'{y}-{m}-{d}')
				}
				runSuperviceList(params).then(res => {
					console.log(JSON.stringify(res));
					if(res.code === 200){
						let temp = {
							categories: res.rows.map(item => { return item.name}),
							series: [
							  {
								name: "事件上报数",
								data: res.rows.map(item => { return item.value})
							  }
							]
						};
						this.chartData = JSON.parse(JSON.stringify(temp));
					}
				})
				params.type="reportForAppCase";
				runSuperviceList(params).then(res => {
					console.log(JSON.stringify(res));
					if(res.code === 200){
						let temp = {
							categories: ['上报数','结案数','立案数','废案数','核实数'],
							series: [
							  {
								name: "事件上报数",
								data: [res.rows[0].SBS,res.rows[0].JAS,res.rows[0].LAS,res.rows[0].FAS,res.rows[0].HSS,]
							  }
							]
						};
						this.chartData1 = JSON.parse(JSON.stringify(temp));
					} 
				})
			  /* //模拟从服务器获取数据时的延时
			  setTimeout(() => {
				
				let res1 = {
					categories: ["2016","2017","2018","2019","2020","2021"],
					series: [
					  {
						name: "事件上报数",
						data: [35,36,31,33,13,34]
					  }
					]
				};
				this.chartData1 = JSON.parse(JSON.stringify(res1));
			  }, 500); */
			},
		},
		onLoad() {
			this.page = 1;
			this.reload = true;
			this.listData = [];
			this.getList();
		},
		onPullDownRefresh(){
			this.page = 1;
			this.reload = true;
			this.listData = [];
			this.getList();
		},
		onReachBottom(){
			this.page++;
			if(this.listData.length < this.total){
				this.status = 'more';
			}else{
				this.status = 'noMore';
				return;
			}
			this.getList();
		}
	}
</script>

<style>
	.uni-padding-wrap {
		padding: 0px 10px;
	}
	.content {
		width: 100%;
		height: auto;
	}
</style>
